package controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import model.Projectdeclaration;
import service.ProjectdelarationService;
import service.impl.ProjectdelarationServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.List;

/**
 * @author CY
 * @date 2022/12/17 10:35
 **/
@WebServlet("/pdsc")
public class ProjectdeclarationSelectBycServlet extends HttpServlet {
    ProjectdelarationService service = new ProjectdelarationServiceImpl();

    //    ArrayList<Projectdeclaration> projects = new ArrayList<>();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求,响应格式
        req.setCharacterEncoding("utf8");
        resp.setContentType("application/json;utf8");
        //解析json
        final BufferedReader bufferedReader = new BufferedReader(req.getReader());
        String line = null;
        final StringBuilder json = new StringBuilder();
        while ((line = bufferedReader.readLine()) != null) {
            json.append(line);
        }
        final JSONObject jsonObject = JSON.parseObject(json.toString());
        final List<Projectdeclaration> ret = service.projectedlarationCheckByc(jsonObject.getInteger("cid"), jsonObject.getInteger("pageIndex"), jsonObject.getInteger("pageSeze"));
        final JSONObject message = new JSONObject();
        message.put("pdcList", ret);
        //返回请求
        resp.getWriter().write(message.toString());
    }
}
